package com.hkyl.hospital.service.impl;

import com.hkyl.hospital.entity.PatientCheck;
import com.hkyl.hospital.mapper.PatientCheckMapper;
import com.hkyl.hospital.mapper.PatientMapper;
import com.hkyl.hospital.mapper.PatientMedicineMapper;
import com.hkyl.hospital.service.PatientCheckService;
import com.hkyl.hospital.service.PatientMedicineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

/**
 * @author hyh
 * @date 2023/07/16 22:38:04
 */
@Service
@Transactional
public class PatientCheckServiceImpl implements PatientCheckService {

    @Autowired
    private PatientCheckMapper patientCheckMapper;
    @Autowired
    private PatientMedicineService patientMedicineService;

    @Override
    public Integer save(PatientCheck patientCheck) {
        Integer patientId = patientCheck.getPatientId();
        BigDecimal price = patientCheck.getPrice();
        Integer billId = patientMedicineService.addOrderAndUpdateBillCostPrice(patientId, "检查费", price);
        patientCheck.setBillId(billId);
        int rows = patientCheckMapper.insertSelective(patientCheck);
        return rows;
    }
}
